#include "threadpool.h"
#include <unistd.h>
#include <stdlib.h>


void *mytask(void *arg)
{
	DBG("thread 0x%x is working on task %d\n",(int)pthread_self(), *(int*)arg);

	int *ptmp = (int *)arg;
	
	sleep(1);

	free(ptmp);

	return NULL;
}

int main(int argc, char *argv[])
{
	ThreadPool_t pool;
	int i = 0;
	
	threadpool_init(&pool, 3);

	for(i = 0; i < 10; i++)
	{
		int *arg = (int *)malloc(sizeof(int));
		if(!arg)
		{
			DBG("err:%d\n",i);
			return -1;
		}
		*arg = i;
		
		threadpool_add_task(&pool,mytask, arg);
	}

	sleep(15);
	
	threadpool_destroy(&pool);

	return 0;
}

